package com.davydov.suabl.model;
import java.awt.Image;
import java.util.ArrayList;
import com.davydov.suabl.Force;
import com.davydov.suabl.Position;
public class BullMonster extends Character {
protected BullMonster(int health, int mass, Position pos, Image avatar) {
	super(health, mass, pos, avatar);
 }
public String getName() {
	return "BullMonster";
 }
 
 @Override
 void die(Environment env) {
	env.remove(this); //will work with real environment
 }
 @Override
 void fire(Environment env) {
	// TODO Auto-generated method stub
	if (this.getVelocity().getDirection() > Math.PI / 2 && this.getVelocity().getDirection() < 3*Math.PI /2)
	{
		this.setNetForce(new Force(0,1));
	}
	else if (this.getVelocity().getDirection() > Math.PI / 2 && this.getVelocity().getDirection() < 3*Math.PI /2)
	{
		this.setNetForce(new Force(Math.PI,1));
	}
 }
 @Override
 public void tick(Environment env) {
	 // TODO Auto-generated method stub
	 //get hero
	 ArrayList<PhysicsObject> creatures = env.getAllObjects();
	 HeroCharacter hero = null;
	 for (int i = 0; i < creatures.size(); i++)
	 {
		 if (env.getAllObjects().get(i) instanceof HeroCharacter)
		 {
			 hero = (HeroCharacter)env.getAllObjects().get(i);
		 }
	 }
	 //if not there, then don't do anything
	 if (hero == null)
	 {
		 return;
	 }
	 //face in the direction of the character (just left or right for now) and call fire
	 if (this.getPosition().getX() < hero.getPosition().getX())
	 {
		 this.getVelocity().setDirection(0);
		 this.fire(env);
	 }
	 else if(this.getPosition().getX() > hero.getPosition().getX())
	 {
		 this.getVelocity().setDirection(Math.PI);
		 this.fire(env);
	 }
 	}
}

